﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using TempCtr.Model;


namespace TempCtr
{
    #pragma warning disable IDE1006 // 命名样式
    public partial class log_query : Form
    {
        public log_query() 
        {
            InitializeComponent();
        }

       
        private void log_query_Load(object sender, EventArgs e)
        {
            

            comboBox1.Items.Clear();
            comboBox2.Items.Clear();

            for (int i = 0; i < Thermostat.ccck+1; i++)
            {
                comboBox1.Items.Add(i);
            }
            comboBox1.SelectedIndex = 0;

            this.MaximizeBox = false;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            start_date.Value = DateTime.Now.AddDays(-1);
            end_date.Value = DateTime.Now;
            start_date.MaxDate = DateTime.Now;
            end_date.MaxDate = DateTime.Now;
            this.start_date.CalendarFont = new Font ("微软雅黑", 50.0f); 
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            DataTable dataTable;
            
            int id = (comboBox1.SelectedIndex-1) * 32 + comboBox2.SelectedIndex+1;

            if (comboBox1.SelectedIndex == 0) id = 0;


            if (radioButton1.Checked)
            {
                dataTable=MySqlHelp.GetTemp(id, start_date.Value, end_date.Value,1);
            }
            else if (radioButton2.Checked)
            {
                dataTable=MySqlHelp.GetTemp(id, start_date.Value, end_date.Value, 2);
            }
            else
            {
                dataTable= MySqlHelp.GetTemp(id, start_date.Value, end_date.Value,0);
            }

            dataGridView1.DataSource = dataTable;

            dataGridView1.RowHeadersVisible = false;
            dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

            label5.Text = "数量:" + dataTable.Rows.Count.ToString();         
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {                  
            comboBox2.Items.Clear();
            if (comboBox1.SelectedIndex == 0)
            {
                comboBox2.Items.Add(0);
            }
            else
            {
                DataTable dataTable = MySqlHelp.GetThermostat(comboBox1.SelectedIndex);
                int num = dataTable.Rows.Count;
                for (int i = 0; i < num; i++)
                {
                    comboBox2.Items.Add(i + 1);
                }
            }           
            comboBox2.SelectedIndex = 0;
        }
    }
}
